﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using System.Reflection;

namespace Lib_Automation
{
    public class Lib_HPReproWF
    {
        public static AutomationPattern NAutomationPattern(AutomationElement obj, AutomationPattern pattern)
        {
            return obj.GetCurrentPattern(pattern) as AutomationPattern;
        }
        
        public static AutomationElement NHPReproHW()
        {
            return NDefAutomationId(AutomationElement.RootElement, TreeScope.Children, "MainDashboardFrame");
        }

        public static AutomationElement NQueueGrid(AutomationElement obj)
        {
            return NDefAutomationId(obj, TreeScope.Descendants, "QueueGrid");
        }

        public static AutomationElement NDefAutomationId(AutomationElement obj, TreeScope tree, string classname)
        {

            return obj.FindFirst(tree, new PropertyCondition(AutomationElement.AutomationIdProperty,classname));
        }

        public static AutomationElementCollection NItemCellDetails(AutomationElement obj)
        {
            return NDefClassName(obj, TreeScope.Children, "DataGridDetailsPresenter");
        }

        public static AutomationElementCollection NQueueItems(AutomationElement obj)
        {
            return NDefClassName(obj, TreeScope.Children, "DataGridRow");
        }

        public static AutomationElementCollection NItemCells(AutomationElement obj)
        {
            return NDefClassName(obj, TreeScope.Children, "DataGridCell");
        }

        public static AutomationElementCollection NQueueHeader(AutomationElement obj)
        {
            return NDefClassName(obj, TreeScope.Children, "DataGridColumnHeadersPresenter");
        }

        public static AutomationElementCollection NQueueHeaderItems(AutomationElement obj)
        {
            return NDefClassName(obj, TreeScope.Children, "DataGridColumnHeader");
        }

        public static AutomationElementCollection NFolder()
        {
            return NDefClassName(AutomationElement.RootElement, TreeScope.Children, "CabinetWClass");
        }
        
        public static AutomationElementCollection NDefClassName(AutomationElement obj, TreeScope tree, string classname)
        {
            return obj.FindAll(tree, new PropertyCondition(AutomationElement.ClassNameProperty, classname));
        }

        public static AutomationElementCollection NCheckBoxs(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.CheckBox);
        }

        public static AutomationElementCollection NComboBoxs(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.ComboBox);
        }

        public static AutomationElementCollection NListItems(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.ListItem);
        }

        public static AutomationElementCollection NButtons(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.Button);
        }

        public static AutomationElementCollection NTexts(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.Text);
        }

        public static AutomationElementCollection NImages(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.Image);
        }

        public static AutomationElementCollection NSeparators(AutomationElement obj)
        {
            return NDefControlType(obj, TreeScope.Descendants, ControlType.Separator);
        }

        public static AutomationElementCollection NDefControlType(AutomationElement obj, TreeScope tree, ControlType controltype)
        {
            return obj.FindAll(tree, new PropertyCondition(AutomationElement.ControlTypeProperty, controltype));
        }
    }
}
